﻿Imports Microsoft.Win32

Public Class GeneralInfo
    Private mFrameworkInstalled As Boolean
    ReadOnly Property CurrentUser As String
        Get
            Return System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()
        End Get
    End Property
    ReadOnly Property Framework As String
        Get
            Dim tString As String = Get45or451FromRegistry()
            Return tString
        End Get
    End Property
    ReadOnly Property VistaOrBetterInstalled As Boolean
        Get
            Dim osVer As Version = Environment.OSVersion.Version
            If osVer.Major = 6 Then Return True
            Return False
        End Get
    End Property
    ReadOnly Property FrameworkInstalled As Boolean
        Get
            mFrameworkInstalled = False
            Dim tString As String = Get45or451FromRegistry()
            If tString <> "" Then mFrameworkInstalled = True
            Return mFrameworkInstalled
        End Get
    End Property
#Region "General Functions"
    Private Function Get45or451FromRegistry() As String
        Try
            Using ndpKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\")
                'ndpKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\")

                Dim releaseKey As Integer = CInt(ndpKey.GetValue("Release"))
                If True Then
                    If releaseKey = 378389 Then
                        Return ".NET Framework 4.5"
                    End If

                    If releaseKey = 378675 Then
                        Return ".NET Framework 4.5.1 installed with Windows 8.1"
                    End If

                    If releaseKey = 378578 Then
                        Return ".NET Framework 4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2"
                    End If

                    If releaseKey = 379893 Then
                        Return ".NET Framework 4.5.2"
                    End If

                    If releaseKey > 378389 Then
                        Return ".NET Framework 4.5 (" & releaseKey & ")"
                    End If
                End If
            End Using
            Return ""
        Catch
            Return ""
        End Try
    End Function
#End Region
End Class
